package com.crungoo.springaop;

import com.crungoo.services.UserService;
import java.lang.reflect.Method;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.framework.ProxyFactory;

/**
 * @author fujc-dev@qq.com
 * @date 2023/7/28 11:13
 */

public class Test {

	public static void main(String[] args) {
		UserService target = new UserService();

		ProxyFactory proxyFactory = new ProxyFactory();
		proxyFactory.setTarget(target);
		//
		proxyFactory.addAdvice(new MethodBeforeAdvice(){

			@Override
			public void before(Method method, Object[] args, Object target) throws Throwable {
				System.out.println("1");
			}
		});
		//
		proxyFactory.addAdvice(new AfterReturningAdvice() {
			@Override
			public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
				System.out.println("2");
			}
		});
		UserService proxy = (UserService) proxyFactory.getProxy();
		proxy.test();
	}
}
